package com.example.demo6.controller;

import com.example.demo6.domain.Movie;
import com.example.demo6.domain.Role;
import com.example.demo6.repository.MovieRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *电影控制器类
 */
@Controller
@RequestMapping(value = "/movie")
public class MovieController {

    @Autowired//自动注入
    private MovieRepository movieRepository;

    //http://localhost:8088/movie/show/{id}
    @RequestMapping(value ="/show/{id}" )
    @ResponseBody
    public Movie show(@PathVariable Long id){
        Movie movie = movieRepository.findOne(id);

        System.out.println("电影名称：" + movie.getName());
        //
        for (Role role: movie.getRoles()) {
            System.out.println("角色名称：" + role.getName() + "， 扮演者:" + role.getActor().getName());
        }
        return movie;

    }

}
